package cn.itrip.common;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/*
        SHA
        SHA256
        MD5  不可逆运算

 */
public class Md5Utils {
        ///对象。方法（参数）
        public static String encodeStr(String oldString){
            try {
                MessageDigest md5=MessageDigest.getInstance("md5");
                byte [] bs=md5.digest(oldString.getBytes());
                //-128  127
                System.out.println("打过后的："+new String(bs));
                StringBuilder sb=new StringBuilder();
                int temp=0;
                for(byte b: bs){
                    temp=b;
                    if(temp<0){
                        //加入
                        temp+=256;
                    }

                   sb.append( Integer.toHexString(temp));

                }
                System.out.println("加密后:"+sb.toString());
                return sb.toString();
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            }


            return "";
        }
//e10adc3949ba59abbe56e057f20f883e
//3ea4839498c59aa845640571cff03e
//e1adc3949ba59abbe56e057f2f883e
//e0adb3949b959aabd56df57f1f873e
    public static void main(String[] args) {
        encodeStr("123456");

    }
}
